import {createRouter,createWebHistory,type Router} from "vue-router";
import {defineAsyncComponent} from "vue";
const {VITE_USER} = import.meta.env; //获取环境变量
const router = createRouter({
    routes: 
    !VITE_USER ?
    [
        {
            path: '/home',
            name: 'home',//主页 
            component: defineAsyncComponent(() => import('../pages/home/index.vue')),
            children:[
                {
                    path:'/attendance',//出勤管理页面
                    name:'attendance',
                    component:defineAsyncComponent(()=>import('@/pages/attendance/index.vue'))
                },{
                    path:'/department',//部门管理页面
                    name:'department',
                    component:defineAsyncComponent(()=>import('@/pages/departmen/index.vue'))
                },{
                    path:'/employee',//员工管理页面
                    name:'employee',
                    component:defineAsyncComponent(()=>import('@/pages/employee/index.vue'))
                },{
                    path:'/leave',//请假管理页面
                    name:'leave',
                    component:defineAsyncComponent(()=>import('@/pages/leave/index.vue'))
                },{
                    path:'/position',
                    name:'position',//岗位管理页面
                    component:defineAsyncComponent(()=>import('@/pages/position/index.vue'))
                },{
                    path:'about',
                    name:'about',//关于
                    component:defineAsyncComponent(()=>import('@/pages/about/index.vue')),
                }
            ]
        },
        {
            path: '/',
            name: 'login',
            component: defineAsyncComponent(() => import('@/pages/login/index.vue'))
        },
    ]:[
        {
            path: '/',
            name: 'login',
            component: defineAsyncComponent(() => import('@/pages/login/index.vue'))
        },{
            path: '/home',
            name: 'about',//主页
            component: defineAsyncComponent(() => import('@/pages/phone/home/index.vue')),
            children:[
                {
                    path:'/message',//消息页面
                    name:'message',
                    component:defineAsyncComponent(()=>import('@/pages/phone/message/index.vue'))
                },{
                    path:'/personal',
                    name:'personal',//个人中心
                    component:defineAsyncComponent(()=>import('@/pages/phone/personal/index.vue'))
                },{
                    path:'card',
                    name:'card',//打卡
                    component:defineAsyncComponent(()=>import('@/pages/phone/card/index.vue'))
                },{
                    path:'/apply',//申请请假和调岗页面
                    name:'apply',
                    component: defineAsyncComponent(()=> import('@/pages/phone/apply/index.vue'))
                }
            ]
        },
    ],
    history:createWebHistory()
})
// 设置拦截器
router.beforeEach((to,from,next)=>{
    next()
})
export default router;